﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AuroraPlugin
{
    public partial class CreateUser : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(Request["userkey"]))
            {
                Response.Write("{\"ResultCode\":\"##resultcode##\"}".Replace("##resultcode##", "-1"));
                return;
            }
            Guid guid;
            if (!Guid.TryParse(Request["userkey"], out guid))
            {
                Response.Write("{\"ResultCode\":\"##resultcode##\"}".Replace("##resultcode##", "-1"));
                return;
            }
            var a = Database.db.Queryable<AP_UserKeys>().Where(it => it.guid == guid).ToList();
            if (a.Count > 0)
            {
                Response.Write("{\"ResultCode\":\"##resultcode##\"}".Replace("##resultcode##", "0"));
                return;
            }
            Database.db.Insertable(new AP_UserKeys() { guid = guid, isbanned = false, machinecode = "Server|" + HttpContext.Current.Request.UserHostAddress, plugins = "0|0" }).ExecuteCommand();
            Response.Write("{\"ResultCode\":\"##resultcode##\"}".Replace("##resultcode##", "1"));
        }
    }
}